﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Zocono.WCS.Domain.PlcBytesObject
{
    public class QTScMessagePlcActionBO : BytesObjectBase
    {
        /// <summary>
        ///    操作方式    0:未选择；1:脱机(手动、半自动、维护等)；2:联机自动；
        /// </summary>
        public short OperationMode { get; set; }

        /// <summary>
        ///  设备状态    0:初始化；1:工作中；2:允许下发任务；3:故障
        /// </summary>
        public short EquipmentStatus { get; set; }

        /// <summary>
        /// 正在执行的任务号码
        /// </summary>
        public int  ExecutedJobNum { get; set; }

        /// <summary>
        /// 货叉1状态   0：无货；1：有货；2：货叉被屏蔽
        /// </summary>
        public short Fork1Status { get; set; }

        /// <summary>
        /// 货叉2状态   0：无货；1：有货；2：货叉被屏蔽
        /// </summary>
        public short Fork2Status { get; set; }

        /// <summary>
        /// 任务执行的阶段  0：无任务流程1：取货行走；2：取货；3：放货行走；4：放货；5：任务完成
        /// </summary>
        public short ProcessState { get; set; }

        /// <summary>
        /// 当前运行目标列
        /// </summary>
        public short CurrentCol { get; set; }

        /// <summary>
        /// 当前运行目标层
        /// </summary>
        public short CurrentLayer { get; set; }

        /// <summary>
        /// YuLiu1 
        /// </summary>
        public short YuLiu1 { get; set; }

        /// <summary>
        /// YuLiu2
        /// </summary>
        public int YuLiu2 { get; set; }

        /// <summary>
        /// YuLiu3
        /// </summary>
        public short YuLiu3 { get; set; }

        /// <summary>
        /// YuLiu4 
        /// </summary>
        public short YuLiu4 { get; set; }

        /// <summary>
        /// YuLiu5
        /// </summary>
        public short YuLiu5 { get; set; }

        /// <summary>
        /// 心跳
        /// </summary>
        public short HeartBeat { get; set; }

        /// <summary>
        /// 故障代码  1	取货位置无货，取货失败	
        ///2	取货位置近端阻挡，无法远端取货 适用于双伸堆垛机
        ///3	卸货位置占位，无法卸货	
        ///4	卸货位置近端阻挡，无法远端卸货 适用于双伸堆垛机
        ///5	货叉无货，无法执行卸货	
        ///6	货叉有货，无法执行取货	
        ///7	任务类型1错误，不符合规则	
        ///8	任务类型2错误，不符合规则	
        ///9	任务类型3错误，不符合规则	
        ///10	任务类型4错误，不符合规则	
        ///11	任务类型8错误，不符合规则	
        ///12	任务类型9错误，不符合规则	
        ///13	卸货任务无法完成，卸货失败	
        ///14	烟温感异常警报	
        ///15	上位急停故障	
        ///16	库位被禁用，任务无法执行	
        ///17	————	
        ///18	————	
        ///19	————	
        ///20	————	
        ///21	堆垛机设备故障
        /// </summary>
        public short FaultCode { get; set; }

        public short YuLiu6 { get; set; }

        public short YuLiu7 { get; set; }

        public override void Serialize(long plcConnectionID, long plcReadDbID, int bytesIndex, int bytesLength, int objectIndex, int objectLength, string objectType, string ScEquipmentCode, byte[] bytes)
        {
            PlcConnectionID = plcConnectionID;
            PlcReadDbID = plcReadDbID;
            BytesIndex = bytesIndex;
            BytesLength = bytesLength;
            ObjectIndex = objectIndex;
            ObjectLength = objectLength;
            /// <summary>
            /// 约定：
            /// 1、设备状态报文以State结尾；
            /// 2、Plc的动作报文以PlcAction结尾；
            /// 3、Wcs的动作报文以WcsAction结尾；
            /// 4、平面PLC报文统一PlcState名称
            /// （后续有其他的再约定）
            /// </summary>
            ObjectType = objectType;
            EquipmentCode = ScEquipmentCode;

            OperationMode = HelperByte.GetIntAt(bytes, 0);

            EquipmentStatus = HelperByte.GetIntAt(bytes, 2);

            ExecutedJobNum = HelperByte.GetDIntAt(bytes, 4);

            Fork1Status = HelperByte.GetIntAt(bytes, 8);

            Fork2Status = HelperByte.GetIntAt(bytes, 10);

            ProcessState = HelperByte.GetIntAt(bytes, 12);

            CurrentCol = HelperByte.GetIntAt(bytes, 14);

            CurrentLayer = HelperByte.GetIntAt(bytes, 16);

            YuLiu1 = HelperByte.GetIntAt(bytes, 18);

            YuLiu2 = HelperByte.GetIntAt(bytes, 20);

            YuLiu3 = HelperByte.GetIntAt(bytes, 24);

            YuLiu4 = HelperByte.GetIntAt(bytes, 26);

            YuLiu5 = HelperByte.GetIntAt(bytes, 28);

            HeartBeat = HelperByte.GetIntAt(bytes, 30);

            FaultCode = HelperByte.GetIntAt(bytes, 32);

        }

    }
}
